<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * 微信客服消息
 */
class CreateWxKfMsg extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //客服消息列表
        Schema::create('wx_kf_msgs', function (Blueprint $table) {
            $table->increments('id')->comment('消息ID');
            $table->string('worker', 100)->default('')->comment('客服帐号');
            $table->string('openid', 100)->default('')->comment('用户标识');
            $table->string('opercode', 10)->default('')->comment('操作码，2002：客服发送信息，2003：客服接收消息');
            $table->mediumText('text')->nullable()->comment('聊天记录');
            $table->timestamp('send_time')->nullable()->comment('消息发送时间');
            $table->softDeletes();
            $table->timestamps();
        });
        //客服聊天用户列表
        Schema::create('wx_kf_users', function (Blueprint $table) {
            $table->increments('id')->comment('消息ID');
            $table->string('openid', 100)->default('')->comment('用户标识');
            $table->mediumText('last_text')->nullable()->comment('最新一次聊天记录');
            $table->timestamp('last_send_time')->nullable()->comment('最新一次发送时间');
            $table->softDeletes();
            $table->timestamps();
            $table->index(['created_at','updated_at'], 'index1');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('wx_kf_msgs');
        Schema::dropIfExists('wx_kf_users');
    }
}
